import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:intl/intl.dart';
import 'package:oli/generated/l10n.dart';
import 'package:oli/router/router.dart';
import 'package:oli/shared/size_fit.dart';
import 'package:oli/shared/theme.dart';
import 'package:oli/viewmodel/text_view_model.dart';
import 'package:provider/provider.dart';

main() {
  runApp(
    MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (ctx) => TextViewModel())
      ],
      child: App()
    )
  );
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // rpx 自适应初始化
    SizeFit.init();

    return MaterialApp(
      localizationsDelegates: [
        S.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: S.delegate.supportedLocales,
      localeListResolutionCallback: (locales, supportedLocales) {
        print('当前系统语言环境$locales');
        return;
      },
      // 在需要配置国际化的地方调用S.of(context).key即可.
      // 没有context 时可以使用S.current.key

      theme: AppTheme.normalTheme,
      darkTheme: AppTheme.darkTheme,

      routes: AppRouter.routes,
      initialRoute: AppRouter.initRoute,
      onGenerateRoute: AppRouter.generateRoute,
      onUnknownRoute: AppRouter.unknownRoute,

      // 去掉右上角 debug 红线
      debugShowCheckedModeBanner: false,
    );
  }

  // void changeLanguage() async {
  //   print('修改前语言环境:${Intl.getCurrentLocale()}');
  //   await S.load(Locale('en', 'US'));
  //
  //   setState刷新页面改变语言
  //   setState(() {});
  //
  //   print('修改后语言环境:${Intl.getCurrentLocale()}');
  // }
}
